import {
  response,
  errorHandle,
  url
} from './response'

const getToken = () => {
  return wx.getStorageSync('auth');
}

export  const experimentSearch = function(data, successCallback, failCallback) {
  wx.request({
    url: `${url}/experiment/search`,
    method: 'get',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}

export const  experimentAdd =  function(data, successCallback, failCallback) {
  wx.request({
    url: `${url}/experiment/add`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}